<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panel header="OPD Membership Discount Matrix" id="reportPrint">

                        <h:panelGrid columns="2" styleClass="alignTop">

                            <p:panel header="Price Matrix" >

                                <p:dataTable id="inwd" value="#{opdMemberShipDiscountController.items}"
                                             filteredValue="#{opdMemberShipDiscountController.filterItems}"
                                             var="a" editable="true" >
                                    <p:column headerText="Membership Scheme" width="150">
                                        <p:autoComplete forceSelection="true"  inputStyle="width:130px;"
                                                        value="#{a.membershipScheme}" 
                                                        completeMethod="#{membershipSchemeController.completeMembershipScheme}" 
                                                        var="mem" itemLabel="#{mem.name}" itemValue="#{mem}" >
                                        </p:autoComplete>
                                    </p:column>

                                    <p:column headerText="Department Name" width="150"
                                              filterBy="#{a.department.name}" filterMatchMode="contains">
                                        <p:autoComplete forceSelection="true" value="#{a.department}" inputStyle="width:130px;"
                                                        completeMethod="#{departmentController.completeDept}" 
                                                        var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" >
                                            <p:column headerText="Department">
                                                <h:outputLabel value="#{dep.name}"/>
                                            </p:column>
                                            <p:column headerText="Institution">
                                                <h:outputLabel value="#{dep.institution.name}"/>
                                            </p:column>
                                        </p:autoComplete>

                                    </p:column>

                                    <p:column headerText="Payment" width="120">
                                        <p:selectOneMenu  value="#{a.paymentMethod}"  >
                                            <f:selectItem itemLabel="Select" />                           
                                            <f:selectItems value="#{enumController.paymentMethods}" />                                    
                                        </p:selectOneMenu>
                                    </p:column>
                                    <p:column  headerText="Discount Percent" width="80">
                                        <h:inputText autocomplete="off" value="#{a.discountPercent}" style="width: 60px;" >
                                        </h:inputText>
                                    </p:column>
                                    <p:column headerText="Actions" width="160">
                                        <p:commandButton ajax="false" value="Update" 
                                                         action="#{opdMemberShipDiscountController.onEdit(a)}"/> 
                                        <p:commandButton ajax="false" value="Delete" action="#{opdMemberShipDiscountController.deleteDepartment}">
                                            <f:setPropertyActionListener value="#{a}" target="#{opdMemberShipDiscountController.current}"/>
                                        </p:commandButton>
                                    </p:column>

                                </p:dataTable>

                                <p:commandButton ajax="false" value="Refresh" 
                                                 action="#{opdMemberShipDiscountController.createItemsDepartments}" />

                            </p:panel>

                            <p:panel header="Add New Matrix" >
                                <p:panelGrid columns="2" >
                                    <h:outputLabel value="Membership Scheme"/>
                                    <p:autoComplete forceSelection="true" 
                                                    value="#{opdMemberShipDiscountController.membershipScheme}" 
                                                    completeMethod="#{membershipSchemeController.completeMembershipScheme}" 
                                                    var="mem" itemLabel="#{mem.name}" itemValue="#{mem}" >
                                    </p:autoComplete>
                                    <h:outputLabel value="Department" />
                                    <p:autoComplete value="#{opdMemberShipDiscountController.department}" 
                                                    forceSelection="true"
                                                    completeMethod="#{departmentController.completeDept}" 
                                                    var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" >
                                        <p:column>
                                            <h:outputLabel value="#{dep.name}"/>
                                        </p:column>
                                        <p:column>
                                            <h:outputLabel value="#{dep.institution.name}"/>
                                        </p:column>
                                    </p:autoComplete>
                                    <h:outputLabel value="Payment Method"/>
                                    <p:selectOneMenu   value="#{opdMemberShipDiscountController.paymentMethod}"  >
                                        <f:selectItem itemLabel="Select" />                           
                                        <f:selectItems value="#{enumController.paymentMethods}" />                                    
                                    </p:selectOneMenu>
                                    <h:outputLabel value="Discount" ></h:outputLabel>
                                    <p:inputText autocomplete="off" value="#{opdMemberShipDiscountController.margin}" />
                                    <h:outputLabel value="" />
                                    <p:commandButton id="btnAdd" value="Add" ajax="false" 
                                                     action="#{opdMemberShipDiscountController.saveSelectedDepartment}" />

                                    <p:defaultCommand target="btnAdd"/>
                                </p:panelGrid>
                                <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                                    <pe:exporter type="xlsx" target="inwd" fileName="Price_metrix_investigation"  />
                                </p:commandButton>

                                <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" >                                         
                                    <p:printer target="reportPrint"/>
                                </p:commandButton>

                            </p:panel>

                        </h:panelGrid>





                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
